package com.sinoglobal.ningxia.activity.interestingGame;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.activity.shop.CashGoodsLogisticsActivity;
import com.sinoglobal.ningxia.beans.AcceptPrizeInfoVo;
import com.sinoglobal.ningxia.downdata.imp.RemoteImpl;
import com.sinoglobal.ningxia.frame.AbstractActivity;
import com.sinoglobal.ningxia.http.Code;

/**
 * 
 * @author zbl
 * @createdate 2014-7-28 下午3:41:43
 * @Description:领奖信息详情
 */
public class AcceptPrizeActivity extends AbstractActivity {
	private TextView name_ed;// 姓名
	private TextView tel;// 电话
	private TextView address;// 地址
	private TextView remark;// 备注
	private TextView company_info;// 物流公司
	private TextView waybill_info;// 运单号码
	private TextView query;// 查询
	private Intent intent;
	private String id;
	private String companyInfo;// 物流编码
	private String waybillInfo;// 运单号码
	private String DELIVERED = "2";// 2代表以及发货，

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_accept_prize);
		titleView.setText(getString(R.string.win_prize_info));
		intent = getIntent();
		id = intent.getStringExtra("id");
		init();
		addListener();
		loadInfo();
	}

	private void loadInfo() {
		new ItktAsyncTaskWithDialog<Void, Void, AcceptPrizeInfoVo>(
				getString(R.string.loading), true, true) {

			@Override
			public AcceptPrizeInfoVo before(Void... params) throws Exception {
				return RemoteImpl.getInstance().getAcceptInfo(id);
			}

			@Override
			public void after(AcceptPrizeInfoVo result) {
				if (result != null) {
					if (Code.CODE_SUCCESS != result.getCode()) {
						// Toast.makeText(AcceptPrizeActivity.this,
						// result.getMessage(), Toast.LENGTH_SHORT).show();
						showShortToastMessage(result.getMessage());
					} else {
						name_ed.setText(result.getYonghu());
						tel.setText(result.getMobile());
						address.setText(result.getAdress());
						remark.setText(result.getNotice());
						// myTask 2代表什么意思
						if (result.getShh_types().equals(DELIVERED)) {
							company_info.setText(result.getPostcompany());
							waybill_info.setText(result.getPostnum());
							query.setVisibility(View.VISIBLE);
							companyInfo = result.getPostcompany();
							waybillInfo = result.getPostnum();
						}
					}
				}

			}

			@Override
			public void exception() {

			}

		}.execute();

	}

	private void addListener() {
		query.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				intent = new Intent(AcceptPrizeActivity.this,
						CashGoodsLogisticsActivity.class);
				intent.putExtra("companyInfo", companyInfo);
				intent.putExtra("waybillInfo", waybillInfo);
				startActivity(intent);
			}
		});
	}

	private void init() {
		name_ed = (TextView) findViewById(R.id.prize_name_ed);
		tel = (TextView) findViewById(R.id.prize_tel);
		address = (TextView) findViewById(R.id.prize_address);
		remark = (TextView) findViewById(R.id.prize_remark);
		company_info = (TextView) findViewById(R.id.prize_company_info);
		waybill_info = (TextView) findViewById(R.id.prize_waybill_info);
		query = (TextView) findViewById(R.id.prize_query);
	}

}
